﻿using Pdelvo.Minecraft.Network;

namespace Pdelvo.Minecraft.Protocol.Packets
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks></remarks>
    public class OpenWindow : Packet
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="OpenWindow"/> class.
        /// </summary>
        /// <remarks></remarks>
        public OpenWindow()
        {
            Code = 0x64;
        }

        /// <summary>
        /// Gets or sets the window ID.
        /// </summary>
        /// <value>The window ID.</value>
        /// <remarks></remarks>
        public byte WindowID { get; set; }
        /// <summary>
        /// Gets or sets the type of the inventory.
        /// </summary>
        /// <value>The type of the inventory.</value>
        /// <remarks></remarks>
        public byte InventoryType { get; set; }
        /// <summary>
        /// Gets or sets the window title.
        /// </summary>
        /// <value>The window title.</value>
        /// <remarks></remarks>
        public string WindowTitle { get; set; }
        /// <summary>
        /// Gets or sets the slots.
        /// </summary>
        /// <value>The slots.</value>
        /// <remarks></remarks>
        public byte Slots { get; set; }

        /// <summary>
        /// Receives the specified reader.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="version">The version.</param>
        /// <remarks></remarks>
        public override void Receive(BigEndianStream reader, int version)
        {
            WindowID = reader.ReadByte();
            InventoryType = reader.ReadByte();
            WindowTitle = reader.ReadString16(100);
            Slots = reader.ReadByte();
        }

        /// <summary>
        /// Sends the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="version">The version.</param>
        /// <remarks></remarks>
        protected override void Send(BigEndianStream writer, int version)
        {
            writer.Write(Code);
            writer.Write(WindowID);
            writer.Write(InventoryType);
            writer.Write(WindowTitle);
            writer.Write(Slots);
        }
    }
}